package com.whcoding.base.project.exception;

import com.whcoding.base.project.common.api.AppCode;
import com.whcoding.base.project.common.api.IResultCode;
import lombok.Getter;

/**
 * @program: spring-boot-learning
 * @description:
 * @author: whcoding
 * @create: 2022-06-30 11:25
 **/

@Getter
public class APIException extends RuntimeException {
	private int code;
	private String message;

	// 手动设置异常
	public APIException(IResultCode statusCode, String message) {
		// message用于用户设置抛出错误详情，例如：当前价格-5，小于0
		super(message);
		// 状态码
		this.code = statusCode.getCode();
		// 状态码配套的msg
		this.message = statusCode.getMessage();
	}

	// 默认异常使用APP_ERROR状态码
	public APIException(String message) {
		super(message);
		this.code = AppCode.APP_ERROR.getCode();
		this.message = AppCode.APP_ERROR.getMessage();
	}

}